
import request  from "../../utils/request.js";


Page({
  data(){
    bannerList:[];
    recommendList:[];
    topMusicList:[]
  },
  onLoad:function(){
    this.getBannerList()
    this.getRecommendList()
    this.getTopMusicList()
  },
  // 获取banner
 async getBannerList(){
    let bannerList =  await request('/banner',{type:2})
    this.setData({
      bannerList:bannerList.banners
    })

  },
  recommond(){
    wx.navigateTo({
      url: '/pages/recommend/recommend',
    })
  },
  async getRecommendList(){
    let recommendList = await request('/personalized',{limit:10})
    
   
      this.setData({
        recommendList:recommendList.result
      })
  },
  async getTopMusicList(){
    let index =0
    let resultArr =[]
    while(index < 5) {
      let topList = await request('/top/list',{idx:index++})
      let topListItem = {name:topList.playlist.name,tracks:topList.playlist.tracks.slice(0,3)} 
      resultArr.push(topListItem)
      this.setData({
        topMusicList:resultArr
      })
    }
  
  }
})
